from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-25 14:02:30.348978
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 25, Apr, 2022
Time: 14:02:36
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.0769
Nobs: 637.000 HQIC: -49.4621
Log likelihood: 7786.77 FPE: 2.58657e-22
AIC: -49.7066 Det(Omega_mle): 2.24823e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.327966 0.062284 5.266 0.000
L1.Burgenland 0.104785 0.039491 2.653 0.008
L1.Kärnten -0.110530 0.020703 -5.339 0.000
L1.Niederösterreich 0.194715 0.082576 2.358 0.018
L1.Oberösterreich 0.120849 0.081447 1.484 0.138
L1.Salzburg 0.258835 0.041936 6.172 0.000
L1.Steiermark 0.044502 0.055145 0.807 0.420
L1.Tirol 0.104301 0.044636 2.337 0.019
L1.Vorarlberg -0.064562 0.039388 -1.639 0.101
L1.Wien 0.025275 0.072179 0.350 0.726
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052633 0.133224 0.395 0.693
L1.Burgenland -0.034929 0.084470 -0.414 0.679
L1.Kärnten 0.041056 0.044283 0.927 0.354
L1.Niederösterreich -0.196822 0.176629 -1.114 0.265
L1.Oberösterreich 0.451943 0.174214 2.594 0.009
L1.Salzburg 0.285433 0.089699 3.182 0.001
L1.Steiermark 0.107743 0.117955 0.913 0.361
L1.Tirol 0.309721 0.095475 3.244 0.001
L1.Vorarlberg 0.023766 0.084250 0.282 0.778
L1.Wien -0.031827 0.154390 -0.206 0.837
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190363 0.031874 5.972 0.000
L1.Burgenland 0.089756 0.020210 4.441 0.000
L1.Kärnten -0.007747 0.010595 -0.731 0.465
L1.Niederösterreich 0.246082 0.042259 5.823 0.000
L1.Oberösterreich 0.159530 0.041681 3.827 0.000
L1.Salzburg 0.040957 0.021461 1.908 0.056
L1.Steiermark 0.026214 0.028221 0.929 0.353
L1.Tirol 0.085048 0.022843 3.723 0.000
L1.Vorarlberg 0.054169 0.020157 2.687 0.007
L1.Wien 0.117217 0.036938 3.173 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110236 0.031956 3.450 0.001
L1.Burgenland 0.044007 0.020261 2.172 0.030
L1.Kärnten -0.013713 0.010622 -1.291 0.197
L1.Niederösterreich 0.176734 0.042367 4.171 0.000
L1.Oberösterreich 0.332042 0.041788 7.946 0.000
L1.Salzburg 0.101746 0.021516 4.729 0.000
L1.Steiermark 0.111597 0.028293 3.944 0.000
L1.Tirol 0.093741 0.022901 4.093 0.000
L1.Vorarlberg 0.060393 0.020209 2.988 0.003
L1.Wien -0.017551 0.037033 -0.474 0.636
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111321 0.059683 1.865 0.062
L1.Burgenland -0.044346 0.037841 -1.172 0.241
L1.Kärnten -0.045666 0.019838 -2.302 0.021
L1.Niederösterreich 0.141041 0.079128 1.782 0.075
L1.Oberösterreich 0.162207 0.078046 2.078 0.038
L1.Salzburg 0.283933 0.040184 7.066 0.000
L1.Steiermark 0.057146 0.052842 1.081 0.279
L1.Tirol 0.161503 0.042772 3.776 0.000
L1.Vorarlberg 0.098653 0.037743 2.614 0.009
L1.Wien 0.076405 0.069165 1.105 0.269
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058401 0.046921 1.245 0.213
L1.Burgenland 0.028460 0.029750 0.957 0.339
L1.Kärnten 0.052222 0.015596 3.348 0.001
L1.Niederösterreich 0.201402 0.062208 3.238 0.001
L1.Oberösterreich 0.328637 0.061357 5.356 0.000
L1.Salzburg 0.038398 0.031591 1.215 0.224
L1.Steiermark 0.008173 0.041543 0.197 0.844
L1.Tirol 0.125453 0.033626 3.731 0.000
L1.Vorarlberg 0.065056 0.029672 2.192 0.028
L1.Wien 0.094682 0.054375 1.741 0.082
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171572 0.056254 3.050 0.002
L1.Burgenland 0.005400 0.035667 0.151 0.880
L1.Kärnten -0.065666 0.018698 -3.512 0.000
L1.Niederösterreich -0.100548 0.074581 -1.348 0.178
L1.Oberösterreich 0.206721 0.073562 2.810 0.005
L1.Salzburg 0.055882 0.037875 1.475 0.140
L1.Steiermark 0.241182 0.049806 4.842 0.000
L1.Tirol 0.501437 0.040314 12.438 0.000
L1.Vorarlberg 0.062593 0.035575 1.759 0.078
L1.Wien -0.076030 0.065191 -1.166 0.244
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.145488 0.062377 2.332 0.020
L1.Burgenland 0.002165 0.039550 0.055 0.956
L1.Kärnten 0.061453 0.020734 2.964 0.003
L1.Niederösterreich 0.175209 0.082700 2.119 0.034
L1.Oberösterreich -0.054286 0.081569 -0.666 0.506
L1.Salzburg 0.208174 0.041998 4.957 0.000
L1.Steiermark 0.137529 0.055228 2.490 0.013
L1.Tirol 0.061423 0.044702 1.374 0.169
L1.Vorarlberg 0.147032 0.039447 3.727 0.000
L1.Wien 0.117889 0.072287 1.631 0.103
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.377433 0.036790 10.259 0.000
L1.Burgenland -0.002135 0.023326 -0.092 0.927
L1.Kärnten -0.021268 0.012229 -1.739 0.082
L1.Niederösterreich 0.208712 0.048776 4.279 0.000
L1.Oberösterreich 0.229086 0.048109 4.762 0.000
L1.Salzburg 0.038727 0.024771 1.563 0.118
L1.Steiermark -0.012602 0.032573 -0.387 0.699
L1.Tirol 0.091642 0.026365 3.476 0.001
L1.Vorarlberg 0.052897 0.023266 2.274 0.023
L1.Wien 0.039751 0.042635 0.932 0.351
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035885 0.111573 0.172704 0.139280 0.101440 0.082894 0.036238 0.209390
Kärnten 0.035885 1.000000 -0.022605 0.132865 0.051293 0.088573 0.443134 -0.063735 0.090920
Niederösterreich 0.111573 -0.022605 1.000000 0.320475 0.126927 0.281832 0.072741 0.158430 0.295000
Oberösterreich 0.172704 0.132865 0.320475 1.000000 0.218782 0.305310 0.168671 0.143606 0.245088
Salzburg 0.139280 0.051293 0.126927 0.218782 1.000000 0.128547 0.094582 0.108992 0.127360
Steiermark 0.101440 0.088573 0.281832 0.305310 0.128547 1.000000 0.139159 0.115346 0.044457
Tirol 0.082894 0.443134 0.072741 0.168671 0.094582 0.139159 1.000000 0.066761 0.150315
Vorarlberg 0.036238 -0.063735 0.158430 0.143606 0.108992 0.115346 0.066761 1.000000 0.000703
Wien 0.209390 0.090920 0.295000 0.245088 0.127360 0.044457 0.150315 0.000703 1.000000